package cn.tedu.tmall.basic.controller;

import cn.tedu.tmall.basic.service.impl.DistricService;
import cn.tedu.tmall.common.pojo.po.DistrictSimplePO;
import cn.tedu.tmall.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dict/district")
@Validated
@Api(tags = "1. 字典数据-省市区")
public class DistricController {
    @Autowired
    private DistricService service;

    @GetMapping("/list-by-parent")
    @ApiOperation("根据父级查询子级地区列表")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParam(name = "parentId",value = "父级ID",required = true,dataType = "long")
    public JsonResult listByParent(@RequestParam @Range(max = 5000,message = "请提交有效的父级单位ID值") Long parentId){
        List<DistrictSimplePO> listByParent = service.listByParent(parentId);
        return JsonResult.ok(listByParent);
    }
}
